﻿jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function (a, b) {
    var x = (a == "-") ? 0 : a.replace(/,/, ".");
    var y = (b == "-") ? 0 : b.replace(/,/, ".");
    x = parseFloat(x);
    y = parseFloat(y);
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function (a, b) {
    var x = (a == "-") ? 0 : a.replace(/,/, ".");
    var y = (b == "-") ? 0 : b.replace(/,/, ".");
    x = parseFloat(x);
    y = parseFloat(y);
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

function ClientDataBegin() {
    $('#client-data-content').html("");
    $.blockUI({
        css:
        {
            width: '700px',
            height: '500px',
            top:  ($(window).height() - 500) /2 + 'px', 
            left: ($(window).width() - 700) /2 + 'px',
        },
        message: $('#loading')
    });
}
function ClientDataSuccess() {
    $.unblockUI();
    $('client-data').append('<div style="clear:both"></div>');
    $('#tabs').tabs('select', '#client-data');
}

function ClientDataFailure() {
    $.unblockUI();
    alert("Error occured!");
}

$(document).ready(function() {
    //            "iDisplayLength": 100,

    $('.dataTable').dataTable({
        "bJQueryUI": true,
        "bSortClasses": false,
        "sPaginationType": "full_numbers",
        "bStateSave": true,
        "aoColumns": [null, null, null, null, null, null, null, null, null, { "sType": "numeric-comma" }, null],
        "oLanguage": {
            "sProcessing": "@Global.DataTable_sProcessing",
            "sLengthMenu": "@Global.DataTable_sLengthMenu",
            "sZeroRecords": "@Global.DataTable_sZeroRecords",
            "sInfo": "@Global.DataTable_sInfo",
            "sInfoEmpty": "@Global.DataTable_sInfoEmpty",
            "sInfoFiltered": "@Global.DataTable_sInfoFiltered",
            "sInfoPostFix": "@Global.DataTable_sInfoPostFix",
            "sSearch": "@Global.DataTable_sSearch",
            "sUrl": "@Global.DataTable_sUrl",
            "oPaginate": {
                "sFirst": "@Global.DataTable_oPaginate_sFirst",
                "sPrevious": "@Global.DataTable_oPaginate_sPrevious",
                "sNext": "@Global.DataTable_oPaginate_sNext",
                "sLast": "@Global.DataTable_oPaginate_sLast"
            }
        }
    });
    $('div .dataTables_wrapper div').each(function () {
        $(this).removeClass("ui-widget-header");
    });

    $('table tbody tr').each(function () {
        $(this).removeClass("ui-state-highlight");
    });

    $('#offers-back-btn').click(function() {
        $tabs.tabs('select', 0);
        return false;
    });
});
